package com.pro.utils;
/**
 * @Author 祖铭泽
 * @Date 2022/01/06
 * @description Date工具类
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private static SimpleDateFormat sdf;
    //日期Date转字符串
    public static String tranferDateToString(Date date){
        sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }
    //日期时间Date转字符串
    public static String tranferDateTimeToString(Date date){
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
    //字符串转日期
    public static Date tranferStringToDate(String date) throws ParseException {
        sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.parse(date);
    }
    //字符串转日期时间
    public static Date tranferStringToDateTime(String date) throws ParseException {
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(date);
    }
}
